package com.yc.boot.work.api;

import afu.org.checkerframework.checker.oigj.qual.O;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yc.boot.common.model.response.Outcome;
import com.yc.boot.sys.model.UserInfo;
import com.yc.boot.work.business.TestzmzBussiness;
import com.yc.boot.work.entity.Test;
import com.yc.boot.work.entity.Testzmz;
import com.yc.boot.work.model.find.TestPage;
import com.yc.boot.work.model.save.SaveTest;
import com.yc.boot.work.model.update.UpdateTest;
import com.yc.boot.work.service.TestzmzService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.Size;
import java.util.List;

/**
 * Create with IntelliT IDEA
 *
 * @Author: zhengmingzhe
 * @Date: 2021/12/08/15:05
 * @Description:
 */
@RestController
@Api(tags = "自行测试Testzmz表的单表增删改查")
@RequestMapping("/testzmz")
public class TestzmzApi {

    @Autowired
    private TestzmzBussiness testzmzBussiness;

    @GetMapping("/queryAll")
    @ApiOperation("查询testzmz表的所有信息 ")
    public Outcome<List<Testzmz>> queryAll(){
        return Outcome.success(testzmzBussiness.queryAll());
    }

    @GetMapping("/getById/{id}")
    @ApiOperation("根据id查询testzmz表")
    public Outcome<Testzmz> getById(@PathVariable Long id){

        return Outcome.success(testzmzBussiness.getById(id));
    }

    @GetMapping("/getByNameOccu/{name}")
    @ApiOperation("根据name精确查询testzmz表")
    public Outcome<Testzmz> getByNameOccu(@PathVariable  String name){
        return Outcome.success(testzmzBussiness.getByNameOccu(name));
    }

    @GetMapping("/getByName/{name}")
    @ApiOperation("根据Name名字进行模糊查询Testzmz表")
    public Outcome<List<Testzmz>> getByName(@PathVariable String name){
        return Outcome.success(testzmzBussiness.getByName(name));
    }

    @GetMapping("/getByTime/")
    @ApiOperation("根据date时间进行范围查询Testzmz表根据创建时间倒序排序")
    public Outcome<List<Testzmz>> getByTime(TestPage date){
        return Outcome.success(testzmzBussiness.getByTime(date));
    }

    @GetMapping("/getByPage/")
    @ApiOperation("对Testzmz表进行分页查询")
    public Outcome<IPage<Testzmz>> getByPage(TestPage page){
        return Outcome.success(testzmzBussiness.queryByPage(page));
    }

    @PostMapping("/saveOnePage/")
    @ApiOperation("对Testzmz表进行单条数据插入")
    public Outcome<Testzmz> save(@RequestBody SaveTest data){
        return Outcome.success(testzmzBussiness.save(data));
    }

    @PostMapping("/saveBatch/")
    @ApiOperation("对Testzmz表进行多条数据数据插入，并设置每次插入的行数")
   public Outcome<Testzmz> saveBatch(@RequestBody  List<SaveTest> savetest,Long size){
        return Outcome.status(testzmzBussiness.saveBatch(savetest,size));
   }

   @PutMapping("/updateById/")
   @ApiOperation("根据Id进行单条数据修改")
   public Outcome<Testzmz> updateById(UpdateTest update){
        return Outcome.status(testzmzBussiness.updateById(update));
   }
    @PutMapping("/updateBatchById/")
    @ApiOperation("方式一根据多个Id进行多条数据修改")
   public Outcome<Testzmz> updateBatchByid(@RequestBody List<UpdateTest> updatebatch){
        return Outcome.status(testzmzBussiness.updateBatchById(updatebatch));
   }
    @PutMapping("/updateBatchByIds/")
    @ApiOperation("方式二根据多个Id进行多条数据修改")
    public Outcome<Testzmz> updateBatchByids(@RequestBody List<UpdateTest> updatebatch){
        return Outcome.status(testzmzBussiness.updateBatchByIds(updatebatch));
    }

    @DeleteMapping("/removeById/")
    @ApiOperation("根据Id进行单条数据删除")
    public Outcome<Testzmz> removeById(Testzmz delete){
        return Outcome.status(testzmzBussiness.removeById(delete));
    }

    @DeleteMapping("/removeBatchByid/")
    @ApiOperation("根据多个Id进行多条数据删除")
    public Outcome<Testzmz> removeBatchByid(@RequestBody @Valid @Size(min = 1)  List<Long> id){
        return Outcome.status(testzmzBussiness.removeBatchByIds(id));
    }
}
